﻿<script lang="ts" name="packspecification" setup>
import { ref, reactive, onMounted } from "vue";
import { ElMessage } from "element-plus";
import type { FormRules } from "element-plus";
import { formatDate } from '/@/utils/formatTime';
import { usePackspecificationApi } from '/@/api/packspecification/packspecification';

//父级传递来的函数，用于回调
const emit = defineEmits(["reloadTable"]);
const packspecificationApi = usePackspecificationApi();
const ruleFormRef = ref();

const state = reactive({
	title: '',
	loading: false,
	showDialog: false,
	ruleForm: {} as any,
	stores: {},
	dropdownData: {} as any,
});

// 自行添加其他规则
const rules = ref<FormRules>({
});

// 页面加载时
onMounted(async () => {
});

// 打开弹窗
const openDialog = async (row: any, title: string) => {
	state.title = title;
	row = row ?? {  };
	state.ruleForm = row.id ? await packspecificationApi.detail(row.id).then(res => res.data.result) : JSON.parse(JSON.stringify(row));
	state.showDialog = true;
};

// 关闭弹窗
const closeDialog = () => {
	emit("reloadTable");
	
	state.showDialog = false;
};

const anei = ref();
const aneis=ref();
const bwai=ref();
const bwais = ref();
const czhan = ref();
const czhans = ref();

// 提交
const submit = async () => {
	state.ruleForm.insideWeight = anei.value + '~' + aneis.value;
	state.ruleForm.outerWeight = bwai.value + '~' + bwais.value;
	state.ruleForm.palletWeight = czhan.value + '~' + czhans.value;
	ruleFormRef.value.validate(async (isValid: boolean, fields?: any) => {
		if (isValid) {
			let values = state.ruleForm;
			await packspecificationApi[state.ruleForm.id ? 'update' : 'add'](values);
			// state.ruleForm.insideWeight = "";
			// state.ruleForm.outerWeight = "";
			// state.ruleForm.palletWeight = "";
			closeDialog();
		} else {
			ElMessage({
				message: `表单有${Object.keys(fields).length}处验证失败，请修改后再提交`,
				type: "error",
			});
		}
	});
};

//将属性或者函数暴露给父组件
defineExpose({ openDialog });
</script>
<template>
	<div class="packspecification-container">
		<el-dialog v-model="state.showDialog" :width="800" draggable :close-on-click-modal="false">
			<template #header>
				<div style="color: #fff">
					<span>{{ state.title }}</span>
				</div>
			</template>
			<el-form :model="state.ruleForm" ref="ruleFormRef" label-width="auto" :rules="rules">
				<el-row :gutter="35">
					<el-form-item v-show="false">
						<el-input v-model="state.ruleForm.id" />
					</el-form-item>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="编码" prop="packCoding">
							<el-input v-model="state.ruleForm.packCoding" placeholder="请输入编码" maxlength="32" show-word-limit clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="名称" prop="packName">
							<el-input v-model="state.ruleForm.packName" placeholder="请输入名称" maxlength="32" show-word-limit clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="混包类型" prop="packType">
							<g-sys-dict v-model="state.ruleForm.packType" code="Package-specifications-for-mixed-package-types" render-as="select" placeholder="请选择混包类型" clearable filterable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="内箱长度" prop="insideLength">
							<el-input-number v-model="state.ruleForm.insideLength" placeholder="请输入内箱长度" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="内箱宽度" prop="insideWidth">
							<el-input-number v-model="state.ruleForm.insideWidth" placeholder="请输入内箱宽度" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="内箱高度" prop="insideHeight">
							<el-input-number v-model="state.ruleForm.insideHeight" placeholder="请输入内箱高度" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="内箱重量" prop="insideWeight">
							<el-input style="width: 100px;" v-model="anei" placeholder="请输入内箱重量" show-word-limit clearable />
							&nbsp;
                            ~
                            &nbsp;
                            <el-input style="width: 100px;" v-model="aneis" placeholder="请输入内箱重量" show-word-limit clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="内箱容量" prop="insideCapaCity">
							<el-input-number v-model="state.ruleForm.insideCapaCity" placeholder="请输入内箱容量" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="外箱长度" prop="outerLength">
							<el-input-number v-model="state.ruleForm.outerLength" placeholder="请输入外箱长度" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="外箱宽度" prop="outerWidth">
							<el-input-number v-model="state.ruleForm.outerWidth" placeholder="请输入外箱宽度" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="外箱高度" prop="outerHeight">
							<el-input-number v-model="state.ruleForm.outerHeight" placeholder="请输入外箱高度" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="外箱重量" prop="outerWeight">
							<el-input style="width: 100px;" v-model="bwai" placeholder="请输入外箱重量" show-word-limit clearable />
							&nbsp;
                            ~
                            &nbsp;
                            <el-input style="width: 100px;" v-model="bwais" placeholder="请输入外箱重量" show-word-limit clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="外箱容量" prop="outerCapaCity">
							<el-input-number v-model="state.ruleForm.outerCapaCity" placeholder="请输入外箱容量" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="栈板长度" prop="palletLength">
							<el-input-number v-model="state.ruleForm.palletLength" placeholder="请输入栈板长度" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="栈板宽度" prop="palletWidth">
							<el-input-number v-model="state.ruleForm.palletWidth" placeholder="请输入栈板宽度" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="栈板高度" prop="palletHeight">
							<el-input-number v-model="state.ruleForm.palletHeight" placeholder="请输入栈板高度" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="栈板重量" prop="palletWeight">
							<el-input style="width: 100px;" v-model="czhan" placeholder="请输入栈板重量" show-word-limit clearable />
							&nbsp;
                            ~
                            &nbsp;
                            <el-input style="width: 100px;" v-model="czhans" placeholder="请输入栈板重量" show-word-limit clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="栈板容量" prop="palletCapaCity">
							<el-input-number v-model="state.ruleForm.palletCapaCity" placeholder="请输入栈板容量" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="描述" prop="packDescribe">
							<el-input v-model="state.ruleForm.packDescribe" placeholder="请输入描述" maxlength="32" type="textarea" show-word-limit clearable />
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="() => state.showDialog = false">取 消</el-button>
					<el-button @click="submit" type="primary" v-reclick="1000">确 定</el-button>
				</span>
			</template>
		</el-dialog>
	</div>
</template>
<style lang="scss" scoped>
:deep(.el-select), :deep(.el-input-number) {
  width: 100%;
}
</style>